
#ifdef D_USE_UI
    #include <QApplication>
#else
    #include <QCoreApplication>
#endif
#include "MacroDefine/GeneralDefine.h"
#include "../mccontrollerthread.h"
#include "../mccontrollerinterpreter.h"
#include "motionthread.h"
#include "../TestUi/motionform.h"

void testForm()
{


}

void test2()
{
    QVector <MoveParameter> motionParaList;
    MoveParameter tmpMovePara;
    PointPro targetPoint;
    targetPoint.jointFlag=0;
    targetPoint.pointNum=9;
    targetPoint.groupNum=1;
    targetPoint.ufValue=0;
    targetPoint.utValue=0;
    targetPoint.recordStatus=1;
    targetPoint.configString="r, t,s ,1,1,1";
    targetPoint.configInt.resize(7);
    targetPoint.positionValue.resize(7);
    targetPoint.positionValue[0]=30;
    targetPoint.positionValue[1]=40;
    targetPoint.positionValue[2]=50;
    targetPoint.positionValue[3]=60;
    targetPoint.positionValue[4]=130;
    targetPoint.positionValue[5]=-30;
    targetPoint.positionValue[6]=90;

    targetPoint.extPositionValue.resize(0);


    tmpMovePara.moveType = ENUM_COMMAND_JOINT;
    tmpMovePara.velocityUnit = ENUM_RATIO;
    tmpMovePara.velocity = 1;
    tmpMovePara.pointType = ENUM_NORMAL_POINT;
    tmpMovePara.targetPoint = targetPoint;
    tmpMovePara.index = 3;
    tmpMovePara.cntRatio = 20;
    tmpMovePara.acc = 65;
    tmpMovePara.lineNumber = 7;


    motionParaList.append(tmpMovePara);


//    targetPoint.jointFlag=0;
//    targetPoint.pointNum=9;
//    targetPoint.groupNum=1;
//    targetPoint.ufValue=0;
//    targetPoint.utValue=0;
//    targetPoint.recordStatus=1;
//    targetPoint.configString="r, t,s ,1,1,1";
//    targetPoint.configInt.resize(7);
//    targetPoint.positionValue.resize(7);
//    targetPoint.positionValue[0]=-30;
//    targetPoint.positionValue[1]=-40;
//    targetPoint.positionValue[2]=-50;
//    targetPoint.positionValue[3]=-60;
//    targetPoint.positionValue[4]=-130;
//    targetPoint.positionValue[5]=-30;
//    targetPoint.positionValue[6]=90;

//    targetPoint.extPositionValue.resize(0);


//    tmpMovePara.moveType = ENUM_COMMAND_JOINT;
//    tmpMovePara.velocityUnit = ENUM_RATIO;
//    tmpMovePara.velocity = 50;
//    tmpMovePara.pointType = ENUM_NORMAL_POINT;
//    tmpMovePara.targetPoint = targetPoint;
//    tmpMovePara.index = 3;
//    tmpMovePara.cntRatio = 20;
//    tmpMovePara.acc = 65;
//    tmpMovePara.lineNumber = 7;


//    motionParaList.append(tmpMovePara);





    McControllerThread mcThread(1);
    McControllerInterpreter* mc;
    mc=mcThread.getControllerInterpreter();

    mc->addTrajectoryCommand(motionParaList);
    mc->startMove();
    mcThread.start();

    MotionThread motionThread(mc);
    motionThread.start();


    while(motionThread.getCallCount()<4000);

    mc->writeDataToFile();
}

// 测试当条ＭＯＶＪ指令
void test1()
{
    QVector <MoveParameter> motionParaList;
    MoveParameter tmpMovePara;
    PointPro targetPoint;
    targetPoint.jointFlag=0;
    targetPoint.pointNum=9;
    targetPoint.groupNum=1;
    targetPoint.ufValue=0;
    targetPoint.utValue=0;
    targetPoint.recordStatus=1;
    targetPoint.configString="r, t,s ,1,1,1";
    targetPoint.configInt.resize(7);
    targetPoint.positionValue.resize(7);
    targetPoint.positionValue[0]=30;
    targetPoint.positionValue[1]=40;
    targetPoint.positionValue[2]=50;
    targetPoint.positionValue[3]=60;
    targetPoint.positionValue[4]=130;
    targetPoint.positionValue[5]=-30;
    targetPoint.positionValue[6]=90;

    targetPoint.extPositionValue.resize(0);


    tmpMovePara.moveType = ENUM_COMMAND_JOINT;
    tmpMovePara.velocityUnit = ENUM_RATIO;
    tmpMovePara.velocity = 50;
    tmpMovePara.pointType = ENUM_NORMAL_POINT;
    tmpMovePara.targetPoint = targetPoint;
    tmpMovePara.index = 3;
    tmpMovePara.cntRatio = 20;
    tmpMovePara.acc = 65;
    tmpMovePara.lineNumber = 7;


    motionParaList.append(tmpMovePara);


//    targetPoint.jointFlag=0;
//    targetPoint.pointNum=9;
//    targetPoint.groupNum=1;
//    targetPoint.ufValue=0;
//    targetPoint.utValue=0;
//    targetPoint.recordStatus=1;
//    targetPoint.configString="r, t,s ,1,1,1";
//    targetPoint.configInt.resize(7);
//    targetPoint.positionValue.resize(7);
//    targetPoint.positionValue[0]=-30;
//    targetPoint.positionValue[1]=-40;
//    targetPoint.positionValue[2]=-50;
//    targetPoint.positionValue[3]=-60;
//    targetPoint.positionValue[4]=-130;
//    targetPoint.positionValue[5]=-30;
//    targetPoint.positionValue[6]=90;

//    targetPoint.extPositionValue.resize(0);


//    tmpMovePara.moveType = ENUM_COMMAND_JOINT;
//    tmpMovePara.velocityUnit = ENUM_RATIO;
//    tmpMovePara.velocity = 50;
//    tmpMovePara.pointType = ENUM_NORMAL_POINT;
//    tmpMovePara.targetPoint = targetPoint;
//    tmpMovePara.index = 3;
//    tmpMovePara.cntRatio = 20;
//    tmpMovePara.acc = 65;
//    tmpMovePara.lineNumber = 7;


//    motionParaList.append(tmpMovePara);





    McControllerThread mcThread(1);
    McControllerInterpreter* mc;
    mc=mcThread.getControllerInterpreter();

    mc->addTrajectoryCommand(motionParaList);
    mc->startMove();
    mcThread.start();

    sleep(1);
    while(0==mc->isTrajectoryEmpty())
    {
        mc->algorithmFunctioncall();
    }

    mcThread.quit();

    mc->writeDataToFile();
}


int main(int argc, char *argv[])
{
#ifdef D_USE_UI
    QApplication a(argc, argv);
#else
    QCoreApplication a(argc, argv);
#endif




   // test2();
    //testForm();

//*******************test form*************************
    //初始　运动线程，解释器
    McControllerThread mcThread(1);
    //获取解释器
    McControllerInterpreter *mcControllerInterpreter=mcThread.getControllerInterpreter();
    //初始　ethercat线程
    MotionThread* ethercatThread=new MotionThread(mcControllerInterpreter);
    //运动线程工作
    mcThread.start();

    //示波器显示
    MotionForm* motionUi=new MotionForm(mcControllerInterpreter);
    motionUi->show();
    //sleep(10);

    //ethercat开始
    ethercatThread->start();



////--------------------------------------------------------

    return a.exec();
}
